﻿@model TestOnlineProject.Models.Entities.CustomTestModel
@using TestOnlineProject.Models.Entities
@{
    ViewBag.Title = "Create";
}
<script src="../../Scripts/jQuery/jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {

        // Change Test Type.
        $('#TestTypeId').change(function () {
            var TestTypeId = $('#TestTypeId').val();
            window.location="@Url.Content("~/Test/Create")?subjectId=@Model.SubjectId&testTypeId=" + TestTypeId;
        });

        // Expires datetime picker.
        $('#datetimepicker').datetimepicker();

        // Clear section name and sectionId when section name is changed.
        $("#section_name").change(function(){
            switch(complete)
            {
           case true:
            $(this).val('');
                $("#SectionId").val('');
                complete = false; 
                break;
            }            
        });        
    });

    // Autpcomplete section.
    var complete = false;
    $(function () {
        $("#section_name").autocomplete({
            source: "@Url.Content("~/Test/AutocompleteSection")?subjectId=@ViewBag.Subject.SubjectId",
            minLength: 1,
            select: function (event, ui) {
                if (ui.item) {
                    $("#section_name").val(ui.item.value);
                    $("#SectionId").val(ui.item.id);
                    $("#section_name").blur();
                    complete = true;
                }
            }
        });
    });

</script>
@{
    if (ViewBag.Section != null)
    {
    <script>
        $(document).ready(function () {
            $("#SectionId").val('@ViewBag.Section.SectionId');
            $("#section_name").val("@ViewBag.Section.Name" +  " @Html.Raw("@") " + "@ViewBag.Section.User.FullName" + " - " + "@ViewBag.Section.User.Username");
        });
    </script>
    }
    else
    {
    <script>
        $(document).ready(function () {
            $("#SectionId").val('');
            $("#section_name").val('');
        });
    </script>
    }
    if (ViewBag.Number != null)
    {
    <script>
            var url = "@Url.Content("~/Test/QuickTest")?id=" + @ViewBag.Number;
//            var win = window.open(url, '_blank', "location=0");
//            win.focus();
    </script>
    }
}
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Subjects", "Index", "Subject")
    / <span style="word-wrap: break-word">@Html.ActionLink((ViewBag.Subject as Subject).Code, "Details", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)</span>
    /
    @Html.ActionLink("Tests", "Index", "Test", new { subjectId = (ViewBag.Subject as Subject).SubjectId }, null)
    / Create Test
</div>
<br />
<div class="main_nav">
    <span><a href="@Url.Content("~/Test/Index")?subjectId=@ViewBag.Subject.SubjectId">
        <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/></a>
</div>
<br />
<div>
    <span class="require_info">(*) is required.</span>
    @using (Html.BeginForm())
    {
        @Html.HiddenFor(model => model.SubjectId)
        @Html.HiddenFor(model => model.UserId)
        <span class="errorMsg">@Html.ValidationSummary(true)</span>
        <table class="table table-bordered">
            <tr>
                <td style="width: 150px; text-align: right">
                    <span>Test Type &nbsp;(*)</span>
                </td>
                <td>
                    <span class="errorMsg">@Html.ValidationMessageFor(model => model.TestTypeId)</span>
                    @Html.DropDownListFor(model => model.TestTypeId, ViewBag.TestTypeList as SelectList, String.Empty)<span></span>
                </td>
            </tr>
            @{
        if (Model.TestTypeId == 1)
        {
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Title&nbsp;(*)</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Title)</span>
                        @Html.TextBoxFor(model => model.Title)<span></span>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Expires&nbsp;(*)</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Expires)</span>
                        <div class="input-append date" id="datetimepicker" data-date="@Model.Expires" data-date-format="yyyy-mm-dd hh:ii"
                        data-link-field="Expires">
                            <input size="16" type="text" value="@Model.Expires" readonly style="width:150px; background-color:White" id="date_time"/>
                            <span class="add-on"><i class="icon-th"></i></span>
                        </div>
                        @Html.HiddenFor(model => model.Expires)
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        Number of Questions&nbsp;(*)
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.NumberOfQuestions)</span>
                        @Html.TextBoxFor(model => model.NumberOfQuestions, new { style = "width:50px" })
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        Duration (minutes)&nbsp;(*)
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Duration)</span>
                        @Html.TextBoxFor(model => model.Duration, new { style = "width:50px" })
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        Section&nbsp;(*)
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.SectionId)</span>
                        <div style="line-height: 1px; margin-bottom: 15px">
                            <input id="section_name" type="text" class="section_name" placeholder="" />
                            <br />
                            @Html.ActionLink("Manage Sections", "Index", "Section", new { subjectId = ViewBag.Subject.SubjectId }, new { target = "_blank" })
                        </div>
                        <ul>
                            <li>Type '/' to view all sections.</li>
                            <li>Type '/m' to view your sections.</li>
                            <li>Type '/a' to view admin sections.</li>
                            <li>Type '/t' o view teacher sections.</li>
                            <li>Type '/s' to view student sections.</li>
                            <li>Type '&#64;[User]' to view seations that created by actual people.</li>
                            <li>Type 'section name' to search by section name.</li>
                        </ul>
                        @Html.HiddenFor(model => model.SectionId)
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" value="Create" class="btn" style="width: 80px">
                            Create</button>
                        @Html.ActionLink("Reset", "Create", new { subjectId = @Model.SubjectId }, new { @class = "btn", style = "width:54px" })
                        @Html.ActionLink("Cancel", "Index", "Test", new { subjectId = @Model.SubjectId }, new { subjectId = @Model.SubjectId, @class = "btn", style = "width:54px" })
                    </td>
                </tr>
        }
        if (Model.TestTypeId == 2)
        {
                <tr>
                    <td style="width: 150px; text-align: right">
                        Section&nbsp;(*)
                    </td>
                    <td>
                        @Html.HiddenFor(model => model.SubjectId)
                        @Html.HiddenFor(model => model.UserId)
                        <input type="hidden" name="Title" id="Title" value="xxxxxxxxxxxx" />
                        <input type="hidden" name="Expires" id="Expires" value="xxxxxxxxxxxx" />
                        <input type="hidden" name="NumberOfQuestions" id="NumberOfQuestions" value="1" />
                        <input type="hidden" name="Duration" id="Duration" value="1" />
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.SectionId)</span>
                        <div style="line-height: 1px; margin-bottom: 15px">
                            <input id="section_name" type="text" class="section_name" placeholder="" />
                            <br />
                            @Html.ActionLink("Manage Sections", "Index", "Section", new { subjectId = ViewBag.Subject.SubjectId }, new { target = "_blank" })
                        </div>
                        <ul>
                            <li>Type '/' to view all sections.</li>
                            <li>Type '/m' to view your sections.</li>
                            <li>Type '/a' to view admin sections.</li>
                            <li>Type '/t' o view teacher sections.</li>
                            <li>Type '/s' to view student sections.</li>
                            <li>Type '&#64;[User]' to view seations that created by actual people.</li>
                            <li>Type 'section name' to search by section name.</li>
                        </ul>
                        @Html.HiddenFor(model => model.SectionId)
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" value="Create" class="btn" style="width: 80px">
                            Create</button>
                        @Html.ActionLink("Reset", "Create", new { subjectId = @Model.SubjectId }, new { @class = "btn", style = "width:54px" })
                        @Html.ActionLink("Cancel", "Index", "Test", new { subjectId = @Model.SubjectId }, new { subjectId = @Model.SubjectId, @class = "btn", style = "width:54px" })
                    </td>
                </tr>
        }
            }
        </table>
                            
    }
</div>
